package com.ssy.lingxi.order.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.order.model.vo.basic.response.DropdownItem;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 送货相关外部状态枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-16
 */
public enum DeliveryOrderOuterStatusEnum {

    ALREADY_SUBMIT(1, "已提交"),

    RECEIVED(2, "已收货"),

    INVALID(3, "已作废"),
    ;

    DeliveryOrderOuterStatusEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 外部状态枚举值
     */
    private Integer code;
    /**
     * 名称
     */
    private String name;

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return LanguageHolder.getName(this.getClass(), this.code);
    }

    /**
     * 根据外部状态枚举值获得外部状态名称
     * @param code 外部状态枚举值
     * @return 外部状态名称
     */
    public static String getNameByCode(Integer code) {
        DeliveryOrderOuterStatusEnum status = Arrays.stream(DeliveryOrderOuterStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return status == null ? "未知" : status.getName();
    }

    /**
     * 获得状态列表
     * @return 前端下拉框内容
     */
    public static List<DropdownItem> toDropdownList() {
        String key = DeliveryOrderOuterStatusEnum.class.getSimpleName().concat(".");
        return Arrays.stream(DeliveryOrderOuterStatusEnum.values()).map(e -> new DropdownItem(e.getCode(), LanguageHolder.getName(key.concat(String.valueOf(e.getCode()))))).collect(Collectors.toList());
    }
}
